package com.xinqi.modules.prepare.discuss.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareDiscussData;
import com.xinqi.modules.prepare.discuss.domain.PrepareDiscussEntity;
import com.xinqi.modules.prepare.discuss.dto.req.PrepareDiscussCreateDTO;
import com.xinqi.modules.prepare.discuss.dto.req.PrepareDiscussUpdateDTO;
import com.xinqi.modules.prepare.discuss.dto.rsp.PrepareDiscussResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区讨论转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareDiscussConvert {

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareDiscussEntity create(PrepareDiscussCreateDTO s);

    public abstract PrepareDiscussCreateDTO create(PrepareDiscussData s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareDiscussEntity update(PrepareDiscussUpdateDTO s, @MappingTarget PrepareDiscussEntity t);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareDiscussEntity update(PrepareDiscussUpdateDTO s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareDiscussResultDTO convert(PrepareDiscussEntity s);

    public abstract PrepareDiscussData convert(PrepareDiscussResultDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareDiscussEntity copy(PrepareDiscussEntity s, @MappingTarget PrepareDiscussEntity t);
}
